package wyh.controller.ServiceRecord;

import com.fasterxml.jackson.databind.ObjectMapper;
import wyh.pojo.ServiceRecord;
import wyh.service.ServiceRecordService;
import wyh.vo.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ServiceRecord/del")
public class DeleteServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


        ObjectMapper ojmapper = new ObjectMapper();
        ServiceRecord pojo = ojmapper.readValue(req.getInputStream(), ServiceRecord.class);
        ServiceRecordService service = new ServiceRecordService();
        Boolean a = service.ServicedeleteById(pojo.getServiceRecordId());
        Result result = null;
        if (a) {
            result = new Result(200, "成功删除", null);
        } else {
            result = new Result(500, "删除失败", null);
        }
        String json = ojmapper.writeValueAsString(result);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(json);
    }
}
